class NotesController < ApplicationController

	layout 'standard'

	before_filter	:login_required
	before_filter :find_repository
	before_filter :find_notes, :only => [ :index ]

	def create
		@note = @repository.notes.new(params[:note])
		if @note.save
			redirect_to url_for(:controller => 'notes', :repository_id => @repository.id)
		else
			render :action => :new
		end
	end

	def edit
		@note = @repository.notes.find(params[:id])
	end

	def update
		@note = @repository.notes.find(params[:id])
		if @note.update_attributes(params[:note])
			redirect_to :controller => 'notes', :repository_id => @repository.id
		else
			render :action => :edit
		end
	end

	def destroy
		@note = @repository.notes.find(params[:id])
		@note.destroy

		redirect_to :controller => 'notes', :repository_id => @repository.id
	end

		protected
			def find_notes
				@notes = @repository.notes
			end
end
